package my.concurrent;

import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public class Semap {


    public static void main(String[] args) {
        AtomicReference<Integer> i = new AtomicReference<>(200);
        Map<Integer, Integer> map = new HashMap<>();

        map.put(1, 1);
        map.put(2, 2);
        map.put(3, 3);
        map.forEach((k,  v) -> {
            i.getAndSet(i.get() + 1);
            v.compareTo(0);
        });

        System.out.println(map);
    }

    @Test
    public void mapForeach() {
        AtomicReference<Integer> i = new AtomicReference<>(200);
        Map<Integer, Integer> map = new HashMap<>();

        map.put(1, 1);
        map.put(2, 2);
        map.put(3, 3);
        map.forEach((k,  v) -> {
            i.getAndSet(i.get() + 1);
            v.compareTo(0);
        });

        System.out.println(map);
    }


}
